package com.atcx.controller;


import com.atcx.pojo.StudentClass;
import com.atcx.service.StudentClassService;
import com.atcx.util.PageResult;
import com.atcx.util.QueryPageBean;
import com.atcx.util.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author pangShu
 * @since 2022-03-23
 */
@RestController
@RequestMapping("/student-class")
public class StudentClassController {

    @Resource
    private StudentClassService studentClassService;
    private Result result;
    @RequestMapping("addStudent")
    public Result addStudent(@RequestBody StudentClass studentClass){
        int i = studentClassService.AddStudent(studentClass);
        if (i>0){
            result = new Result(true,"添加学生成功");
        }else {
            result = new Result(false,"添加学生失败");
        }
        return result;
    }

    //删除
    @RequestMapping("deleteStudent")
    public Result deleteStudent(int id){
        int i = studentClassService.deleteStudent(id);
        if (i>0){
            result = new Result(true,"删除学生信息成功");
        }else {
            result = new Result(false,"删除学生信息失败");
        }
        return result;
    }
    //分页查询
    @RequestMapping("findByPage")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean){
        PageResult page = studentClassService.findByPage(queryPageBean);
        if (page != null){
            result = new Result(true,"查询学生信息成功",page);
        }else {
            result = new Result(false,"查询学生信息失败");
        }
        return result;

    }
}

